<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"> <style>
	.KEYW {color: #933;}
	.COMM {color: #bbb; font-style: italic;}
	.NUMB {color: #393;}
	.STRN {color: #393;}
	.REGX {color: #339;}
	.line {border-right: 1px dotted #666; color: #666; font-style: normal;}
	</style></head><body><pre><span class='line'>  1</span> <span class="COMM">/*----------------------------------------------------------------------------
<span class='line'>  2</span>  | Copyright (c) 2009 Matthew B. Brophy (matt@brophy.org).  
<span class='line'>  3</span>  | Liscense: MIT License (http://www.opensource.org/licenses/mit-license.php)
<span class='line'>  4</span>  |
<span class='line'>  5</span>  | $Id$
<span class='line'>  6</span>  -----------------------------------------------------------------------------*/</span><span class="WHIT">
<span class='line'>  7</span> 
<span class='line'>  8</span> </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">org</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="STRN">"undefined"</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'>  9</span> </span><span class="WHIT">    </span><span class="NAME">org</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="NAME">org</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 10</span> </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">org.brophy</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="STRN">"undefined"</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'> 11</span> </span><span class="WHIT">    </span><span class="NAME">org.brophy</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="NAME">org.brophy</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 12</span> </span><span class="KEYW">if</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">typeof</span><span class="WHIT"> </span><span class="NAME">org.brophy.js</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="STRN">"undefined"</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'> 13</span> </span><span class="WHIT">    </span><span class="NAME">org.brophy.js</span><span class="WHIT"> </span><span class="PUNC">==</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="NAME">org.brophy.js</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'> 14</span> 
<span class='line'> 15</span> </span><span class="COMM">/** 
<span class='line'> 16</span>  * @namespace 
<span class='line'> 17</span>  * @description Dragging namespace in the org.brophy.js JavaScript library 
<span class='line'> 18</span>  * @requires    This library requires the &lt;a href="http://www.mochikit.com">
<span class='line'> 19</span>  *              MochiKit&lt;/a> JavaScript library 
<span class='line'> 20</span>  *              (version 1.4+).
<span class='line'> 21</span>  */</span><span class="WHIT">
<span class='line'> 22</span> </span><span class="NAME">org.brophy.js.drag</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 23</span> 
<span class='line'> 24</span> </span><span class="COMM">/**
<span class='line'> 25</span>  * @constructor
<span class='line'> 26</span>  * @description 
<span class='line'> 27</span>  *   The Dragger class lets you easily add drag and drop 
<span class='line'> 28</span>  *   funcitonality to any element.  Simply create a new Dragger()
<span class='line'> 29</span>  *   object with whatever options you like, and then call the 
<span class='line'> 30</span>  *   Dragger.setElementDraggable() on all the elements you 
<span class='line'> 31</span>  *   would like to be able to drag.
<span class='line'> 32</span>  *   &lt;br>&lt;br>
<span class='line'> 33</span>  *   In the options below that are functions, you can use the methods
<span class='line'> 34</span>  *   this.getOriginalNode() and this.getTargetNode() to retrieve the
<span class='line'> 35</span>  *   node we started dragging and the node we are actually dragging,
<span class='line'> 36</span>  *   respectively, as well as this.getEvent() to get the event that 
<span class='line'> 37</span>  *   was fired.
<span class='line'> 38</span>  *
<span class='line'> 39</span>  * @param options
<span class='line'> 40</span>  *    This is an object that can have the following options, and 
<span class='line'> 41</span>  *    their (type) and [default] values:&lt;br/>&lt;br/>
<span class='line'> 42</span>  *    &lt;ul>
<span class='line'> 43</span>  *      &lt;li>&lt;b>cloneNode&lt;/b> (boolean) [false] &lt;/li>
<span class='line'> 44</span>  *        Should we clone the node we clicked on and drag that instead?
<span class='line'> 45</span>  *      &lt;br>&lt;br>
<span class='line'> 46</span>  *      &lt;li>&lt;b>getClonedNode&lt;/b> (function) [null] &lt;/li>
<span class='line'> 47</span>  *        Advanced function to create a different node to drag instead 
<span class='line'> 48</span>  *        of the original node we clicked on.  &lt;br>
<span class='line'> 49</span>  *         - Takes no parameters&lt;br>
<span class='line'> 50</span>  *         - Should return the new node to drag
<span class='line'> 51</span>  *      &lt;br>&lt;br>
<span class='line'> 52</span>  *      &lt;li>&lt;b>removeElement&lt;/b> (boolean) [false] &lt;/li>
<span class='line'> 53</span>  *      Should we remove the dragged element from the DOM when we finish? 
<span class='line'> 54</span>  *      &lt;br>&lt;br> 
<span class='line'> 55</span>  *      &lt;li>&lt;b>opacity&lt;/b> (float) [0.5] &lt;/li>
<span class='line'> 56</span>  *      Opacity value between 0 and 1 for the dragged element 
<span class='line'> 57</span>  *      &lt;br>&lt;br>
<span class='line'> 58</span>  *      &lt;li>&lt;b>snap&lt;/b> (integer) [1] &lt;/li>
<span class='line'> 59</span>  *      While dragging, snap the element every 'n' pixels from it's
<span class='line'> 60</span>  *      original location
<span class='line'> 61</span>  *      &lt;br>&lt;br>
<span class='line'> 62</span>  *      &lt;li>&lt;b>disableVertical&lt;/b> (boolean) [false] &lt;/li>
<span class='line'> 63</span>  *      Disable vertical dragging of the element
<span class='line'> 64</span>  *      &lt;br>&lt;br>
<span class='line'> 65</span>  *      &lt;li>&lt;b>disableHorizontal&lt;/b> (boolean) [false] &lt;/li>
<span class='line'> 66</span>  *      Disable horizontal dragging of the element
<span class='line'> 67</span>  *      &lt;br>&lt;br>
<span class='line'> 68</span>  *      &lt;li>&lt;b>escapeToCancel&lt;/b> (boolean) [true] &lt;/li>
<span class='line'> 69</span>  *      Whether or not pressing the Escape key while dragging should 
<span class='line'> 70</span>  *      cancel the drag
<span class='line'> 71</span>  *      &lt;br>&lt;br>
<span class='line'> 72</span>  *      &lt;li>&lt;b>onStart&lt;/b> (function) [null] &lt;/li>
<span class='line'> 73</span>  *      Function to run at the beginning of a drag&lt;br>
<span class='line'> 74</span>  *        - Takes no parameters
<span class='line'> 75</span>  *      &lt;br>&lt;br>  
<span class='line'> 76</span>  *      &lt;li>&lt;b>onDrag&lt;/b> (function) [null] &lt;/li>
<span class='line'> 77</span>  *      Function to run with each onmousemove event during a drag&lt;br>
<span class='line'> 78</span>  *        - Takes no parameters
<span class='line'> 79</span>  *      &lt;br>&lt;br>  
<span class='line'> 80</span>  *      &lt;li>&lt;b>onStop&lt;/b> (function) [null] &lt;/li>
<span class='line'> 81</span>  *      Function to run at the end of a successful drag&lt;br>
<span class='line'> 82</span>  *        - Takes a boolean parameter indicating whether this stop 
<span class='line'> 83</span>  *          was caused by a user cancel or not
<span class='line'> 84</span>  *    &lt;/ul>
<span class='line'> 85</span>  */</span><span class="WHIT">
<span class='line'> 86</span> </span><span class="NAME">org.brophy.js.drag.Dragger</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">options</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 87</span> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 88</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'> 89</span>    * @private
<span class='line'> 90</span>    */</span><span class="WHIT">
<span class='line'> 91</span> </span><span class="WHIT">  </span><span class="NAME">this._init</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'> 92</span> </span><span class="WHIT">  </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 93</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">MS</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">MochiKit.Style</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'> 94</span> </span><span class="WHIT">    </span><span class="NAME">this._mouseup</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">     </span><span class="COMM">// onmouseup id</span><span class="WHIT">
<span class='line'> 95</span> </span><span class="WHIT">    </span><span class="NAME">this._mousemove</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">   </span><span class="COMM">// onmousemove id</span><span class="WHIT">
<span class='line'> 96</span> </span><span class="WHIT">    </span><span class="NAME">this._keyup</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">       </span><span class="COMM">// onkeydown id</span><span class="WHIT">
<span class='line'> 97</span> </span><span class="WHIT">    </span><span class="NAME">this._original</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">    </span><span class="COMM">// Element clicked on</span><span class="WHIT">
<span class='line'> 98</span> </span><span class="WHIT">    </span><span class="NAME">this._target</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">      </span><span class="COMM">// Element we are dragging</span><span class="WHIT">
<span class='line'> 99</span> </span><span class="WHIT">    </span><span class="NAME">this._event</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">       </span><span class="COMM">// The event that was fired.</span><span class="WHIT">
<span class='line'>100</span> </span><span class="WHIT">    </span><span class="NAME">this._offset</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">      </span><span class="COMM">// Offset from mouse</span><span class="WHIT">
<span class='line'>101</span> </span><span class="WHIT">    </span><span class="NAME">this._moved</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">;</span><span class="WHIT">      </span><span class="COMM">// Have we moved at all?</span><span class="WHIT">
<span class='line'>102</span> </span><span class="WHIT">    </span><span class="NAME">this._originalStyle</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="COMM">// Store the original styles</span><span class="WHIT">
<span class='line'>103</span> </span><span class="WHIT">    </span><span class="NAME">this._originalPosition</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">             </span><span class="COMM">// Store the original position</span><span class="WHIT">
<span class='line'>104</span> </span><span class="WHIT">    </span><span class="NAME">this._snapDiff</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">MS.Coordinates</span><span class="PUNC">(</span><span class="NUMB">0</span><span class="PUNC">,</span><span class="NUMB">0</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">  </span><span class="COMM">// Store the snap difference</span><span class="WHIT">
<span class='line'>105</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>106</span> 
<span class='line'>107</span> </span><span class="WHIT">  </span><span class="NAME">this._defaultOptions</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'>108</span> </span><span class="WHIT">  </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>109</span> </span><span class="WHIT">    </span><span class="COMM">/* Function to create a cloned node to actually drag.  Should 
<span class='line'>110</span>        accept a MochiKit event object as a parameter, and return a 
<span class='line'>111</span>        node that has been inserted into the DOM */</span><span class="WHIT">
<span class='line'>112</span> </span><span class="WHIT">    </span><span class="STRN">'getClonedNode'</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>113</span> 
<span class='line'>114</span> </span><span class="WHIT">    </span><span class="COMM">/* Simple option to just clone the node */</span><span class="WHIT">
<span class='line'>115</span> </span><span class="WHIT">    </span><span class="STRN">'cloneNode'</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>116</span> 
<span class='line'>117</span> </span><span class="WHIT">    </span><span class="COMM">/* Remove the dragged element from the DOM when we finish? */</span><span class="WHIT">
<span class='line'>118</span> </span><span class="WHIT">    </span><span class="STRN">'removeElement'</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>119</span> </span><span class="WHIT">  </span><span class="WHIT">
<span class='line'>120</span> </span><span class="WHIT">    </span><span class="COMM">/* Opacity value between 0 and 1 for the dragged element */</span><span class="WHIT">
<span class='line'>121</span> </span><span class="WHIT">    </span><span class="STRN">'opacity'</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NUMB">0.5</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>122</span> 
<span class='line'>123</span> </span><span class="WHIT">    </span><span class="COMM">/* Snap the element every 'n' pixels */</span><span class="WHIT">
<span class='line'>124</span> </span><span class="WHIT">    </span><span class="STRN">'snap'</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>125</span> 
<span class='line'>126</span> </span><span class="WHIT">    </span><span class="COMM">/* Disable vertical dragging */</span><span class="WHIT">
<span class='line'>127</span> </span><span class="WHIT">    </span><span class="STRN">'disableVertical'</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>128</span> 
<span class='line'>129</span> </span><span class="WHIT">    </span><span class="COMM">/* Disable horizontal dragging */</span><span class="WHIT">
<span class='line'>130</span> </span><span class="WHIT">    </span><span class="STRN">'disableHorizontal'</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>131</span> 
<span class='line'>132</span> </span><span class="WHIT">    </span><span class="COMM">/* Escape to Cancel */</span><span class="WHIT">
<span class='line'>133</span> </span><span class="WHIT">    </span><span class="STRN">'escapeToCancel'</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>134</span> 
<span class='line'>135</span> </span><span class="WHIT">    </span><span class="COMM">/* Function to run at the beginning of a drag
<span class='line'>136</span>         - Takes no parameters
<span class='line'>137</span>         - Should return the updated element */</span><span class="WHIT">
<span class='line'>138</span> </span><span class="WHIT">    </span><span class="STRN">'onStart'</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>139</span> </span><span class="WHIT">    </span><span class="WHIT">
<span class='line'>140</span> </span><span class="WHIT">    </span><span class="COMM">/* Function to run with each onmousemove event during a drag
<span class='line'>141</span>         - Takes no parameters
<span class='line'>142</span>         - Should return the updated element */</span><span class="WHIT">
<span class='line'>143</span> </span><span class="WHIT">    </span><span class="STRN">'onDrag'</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>144</span> </span><span class="WHIT">    </span><span class="WHIT">
<span class='line'>145</span> </span><span class="WHIT">    </span><span class="COMM">/* Function to run at the end of a successful drag
<span class='line'>146</span>         - Takes no parameters
<span class='line'>147</span>         - Should return the updated element */</span><span class="WHIT">
<span class='line'>148</span> </span><span class="WHIT">    </span><span class="STRN">'onStop'</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>149</span> </span><span class="WHIT">    </span><span class="WHIT">
<span class='line'>150</span> </span><span class="WHIT">    </span><span class="COMM">/* Additional options?
<span class='line'>151</span>         - More useful defaults?
<span class='line'>152</span>           - Cloning boolean option?
<span class='line'>153</span>         - Click Validator?
<span class='line'>154</span>         - Handles for Dragging?
<span class='line'>155</span>         - Separate resizing library? 
<span class='line'>156</span>         
<span class='line'>157</span>         
<span class='line'>158</span>     */</span><span class="WHIT">
<span class='line'>159</span> </span><span class="WHIT">    </span><span class="STRN">'_'</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="WHIT">
<span class='line'>160</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>161</span> 
<span class='line'>162</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'>163</span>    * @private
<span class='line'>164</span>    */</span><span class="WHIT">
<span class='line'>165</span> </span><span class="WHIT">  </span><span class="NAME">this._checkFuncEffects</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">funcName</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>166</span> </span><span class="WHIT">  </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>167</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">MochiKit.Base.isUndefinedOrNull</span><span class="PUNC">(</span><span class="NAME">this._target</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>168</span> </span><span class="WHIT">    </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>169</span> </span><span class="WHIT">      </span><span class="KEYW">throw</span><span class="PUNC">(</span><span class="STRN">"org.brophy.js.drag.js: The specified "</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="NAME">funcName</span><span class="WHIT"> </span><span class="PUNC">+</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'>170</span> </span><span class="WHIT">            </span><span class="STRN">" function must return the new element."</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>171</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>172</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>173</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>174</span> 
<span class='line'>175</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'>176</span>    * @private
<span class='line'>177</span>    */</span><span class="WHIT">
<span class='line'>178</span> </span><span class="WHIT">  </span><span class="NAME">this._keyupfunc</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">e</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>179</span> </span><span class="WHIT">  </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>180</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">this.escapeToCancel</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="NAME">e.key</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">string</span><span class="WHIT"> </span><span class="PUNC">===</span><span class="WHIT"> </span><span class="STRN">"KEY_ESCAPE"</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>181</span> </span><span class="WHIT">      </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="NAME">this._stop</span><span class="PUNC">(</span><span class="NAME">e</span><span class="PUNC">,</span><span class="KEYW">true</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>182</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>183</span> 
<span class='line'>184</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'>185</span>    * @private
<span class='line'>186</span>    */</span><span class="WHIT">
<span class='line'>187</span> </span><span class="WHIT">  </span><span class="NAME">this._diff</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">lhs</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">rhs</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'>188</span> </span><span class="WHIT">  </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'>189</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">MS</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">MochiKit.Style</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>190</span> </span><span class="WHIT">    </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">MochiKit.Style.Coordinates</span><span class="PUNC">(</span><span class="WHIT">
<span class='line'>191</span> </span><span class="WHIT">      </span><span class="PUNC">(</span><span class="NAME">this.disableHorizontal</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'>192</span> </span><span class="WHIT">        </span><span class="NAME">MS.getElementPosition</span><span class="PUNC">(</span><span class="NAME">this._target</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">x</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'>193</span> </span><span class="WHIT">        </span><span class="NAME">parseInt</span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NAME">lhs.x</span><span class="PUNC">-</span><span class="NAME">rhs.x</span><span class="PUNC">)</span><span class="PUNC">/</span><span class="NAME">this.snap</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">10</span><span class="PUNC">)</span><span class="PUNC">*</span><span class="NAME">this.snap</span><span class="PUNC">+</span><span class="NAME">this._snapDiff.x</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>194</span> </span><span class="WHIT">      </span><span class="PUNC">(</span><span class="NAME">this.disableVertical</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'>195</span> </span><span class="WHIT">        </span><span class="NAME">MS.getElementPosition</span><span class="PUNC">(</span><span class="NAME">this._target</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">y</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT">
<span class='line'>196</span> </span><span class="WHIT">        </span><span class="NAME">parseInt</span><span class="PUNC">(</span><span class="PUNC">(</span><span class="NAME">lhs.y</span><span class="PUNC">-</span><span class="NAME">rhs.y</span><span class="PUNC">)</span><span class="PUNC">/</span><span class="NAME">this.snap</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NUMB">10</span><span class="PUNC">)</span><span class="PUNC">*</span><span class="NAME">this.snap</span><span class="PUNC">+</span><span class="NAME">this._snapDiff.y</span><span class="WHIT"> </span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>197</span> 
<span class='line'>198</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>199</span> 
<span class='line'>200</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'>201</span>    * @private
<span class='line'>202</span>    */</span><span class="WHIT">
<span class='line'>203</span> </span><span class="WHIT">  </span><span class="NAME">this._drag</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">e</span><span class="PUNC">,</span><span class="NAME">fromStart</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>204</span> </span><span class="WHIT">  </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>205</span> </span><span class="WHIT">    </span><span class="NAME">fromStart</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">MochiKit.Base.isUndefinedOrNull</span><span class="PUNC">(</span><span class="NAME">fromStart</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">fromStart</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>206</span> </span><span class="WHIT">    </span><span class="NAME">this._event</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">e</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>207</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">this._moved</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'>208</span> </span><span class="WHIT">      </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="NAME">MochiKit.Style.setStyle</span><span class="PUNC">(</span><span class="NAME">this._target</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="STRN">'position'</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="STRN">'absolute'</span><span class="PUNC">}</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>209</span> </span><span class="WHIT">    </span><span class="NAME">MochiKit.Style.setElementPosition</span><span class="PUNC">(</span><span class="NAME">this._target</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'>210</span> </span><span class="WHIT">                                      </span><span class="NAME">this._diff</span><span class="PUNC">(</span><span class="NAME">e.mouse</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">page</span><span class="PUNC">,</span><span class="WHIT">
<span class='line'>211</span> </span><span class="WHIT">                                                 </span><span class="NAME">this._offset</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>212</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">fromStart</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="NAME">this._moved</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>213</span> 
<span class='line'>214</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">MochiKit.Base.isUndefinedOrNull</span><span class="PUNC">(</span><span class="NAME">this.onDrag</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="NAME">this.onDrag</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>215</span> 
<span class='line'>216</span> </span><span class="WHIT">    </span><span class="COMM">// Prevent the event from propogating</span><span class="WHIT">
<span class='line'>217</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">fromStart</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'>218</span> </span><span class="WHIT">    </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'>219</span> </span><span class="WHIT">      </span><span class="NAME">e.stop</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>220</span> </span><span class="WHIT">      </span><span class="NAME">this._event</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>221</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>222</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>223</span> 
<span class='line'>224</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'>225</span>    * @private
<span class='line'>226</span>    */</span><span class="WHIT">
<span class='line'>227</span> </span><span class="WHIT">  </span><span class="NAME">this._stop</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">e</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">cancel</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>228</span> </span><span class="WHIT">  </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>229</span> </span><span class="WHIT">    </span><span class="NAME">this._event</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">e</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'>230</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">MS</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">MochiKit.Style</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>231</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">MD</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">MochiKit.DOM</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>232</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">MB</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">MochiKit.Base</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>233</span> 
<span class='line'>234</span> </span><span class="WHIT">    </span><span class="NAME">cancel</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">MB.isUndefinedOrNull</span><span class="PUNC">(</span><span class="NAME">cancel</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="KEYW">false</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="NAME">cancel</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>235</span> 
<span class='line'>236</span> </span><span class="WHIT">    </span><span class="NAME">MochiKit.Signal.disconnect</span><span class="PUNC">(</span><span class="NAME">this._mousemove</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>237</span> </span><span class="WHIT">    </span><span class="NAME">MochiKit.Signal.disconnect</span><span class="PUNC">(</span><span class="NAME">this._mouseup</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">  </span><span class="WHIT">
<span class='line'>238</span> </span><span class="WHIT">    </span><span class="NAME">MochiKit.Signal.disconnect</span><span class="PUNC">(</span><span class="NAME">this._keyup</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">  </span><span class="WHIT">
<span class='line'>239</span> </span><span class="WHIT">      </span><span class="WHIT">
<span class='line'>240</span> </span><span class="WHIT">    </span><span class="COMM">// If we are supposed to remove, or if we created a new element </span><span class="WHIT">
<span class='line'>241</span> </span><span class="WHIT">    </span><span class="COMM">// and didn't move it at all we need to get rid of it as it </span><span class="WHIT">
<span class='line'>242</span> </span><span class="WHIT">    </span><span class="COMM">// is currently sitting directly on top of us.</span><span class="WHIT">
<span class='line'>243</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">cancel</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>244</span> </span><span class="WHIT">    </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>245</span> </span><span class="WHIT">      </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">this._target</span><span class="WHIT"> </span><span class="PUNC">!=</span><span class="WHIT"> </span><span class="NAME">this._original</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>246</span> </span><span class="WHIT">      </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>247</span> </span><span class="WHIT">        </span><span class="NAME">MD.removeElement</span><span class="PUNC">(</span><span class="NAME">this._target</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>248</span> </span><span class="WHIT">      </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>249</span> </span><span class="WHIT">      </span><span class="KEYW">else</span><span class="WHIT">
<span class='line'>250</span> </span><span class="WHIT">      </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>251</span> </span><span class="WHIT">        </span><span class="NAME">this._resetTarget</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>252</span> </span><span class="WHIT"> </span><span class="WHIT">
<span class='line'>253</span> </span><span class="WHIT">        </span><span class="COMM">// We didn't clone, put us back where we started</span><span class="WHIT">
<span class='line'>254</span> </span><span class="WHIT">        </span><span class="NAME">MS.setElementPosition</span><span class="PUNC">(</span><span class="NAME">this._target</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">this._originalPosition</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>255</span> </span><span class="WHIT">      </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>256</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>257</span> </span><span class="WHIT">    </span><span class="KEYW">else</span><span class="WHIT"> </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="WHIT"> </span><span class="NAME">this.removeElement</span><span class="WHIT"> </span><span class="PUNC">||</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'>258</span> </span><span class="WHIT">           </span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">this._moved</span><span class="WHIT"> </span><span class="PUNC">&&</span><span class="WHIT"> </span><span class="NAME">this._original</span><span class="WHIT"> </span><span class="PUNC">!=</span><span class="WHIT"> </span><span class="NAME">this._target</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>259</span> </span><span class="WHIT">    </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>260</span> </span><span class="WHIT">      </span><span class="NAME">MD.removeElement</span><span class="PUNC">(</span><span class="NAME">this._target</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>261</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>262</span> </span><span class="WHIT">    </span><span class="KEYW">else</span><span class="WHIT">
<span class='line'>263</span> </span><span class="WHIT">    </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>264</span> </span><span class="WHIT">      </span><span class="NAME">this._resetTarget</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>265</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>266</span> 
<span class='line'>267</span> </span><span class="WHIT">    </span><span class="COMM">// Run the user specified onStop function</span><span class="WHIT">
<span class='line'>268</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">MB.isUndefinedOrNull</span><span class="PUNC">(</span><span class="NAME">this.onStop</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="NAME">this.onStop</span><span class="PUNC">(</span><span class="NAME">cancel</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>269</span> </span><span class="WHIT">    </span><span class="NAME">this._event</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>270</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>271</span> 
<span class='line'>272</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'>273</span>    * @private
<span class='line'>274</span>    */</span><span class="WHIT">
<span class='line'>275</span> </span><span class="WHIT">  </span><span class="NAME">this._resetTarget</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>276</span> </span><span class="WHIT">  </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>277</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">MS</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">MochiKit.Style</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>278</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">MD</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">MochiKit.DOM</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>279</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">MB</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">MochiKit.Base</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>280</span> 
<span class='line'>281</span> </span><span class="WHIT">    </span><span class="COMM">// Reset any original attributes about the object</span><span class="WHIT">
<span class='line'>282</span> 
<span class='line'>283</span> </span><span class="WHIT">    </span><span class="COMM">/* Handle opacity by itself due to cross browser issues */</span><span class="WHIT">
<span class='line'>284</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">MB.isUndefinedOrNull</span><span class="PUNC">(</span><span class="NAME">this._originalStyle.opacity</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>285</span> </span><span class="WHIT">    </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>286</span> </span><span class="WHIT">      </span><span class="NAME">MS.setOpacity</span><span class="PUNC">(</span><span class="NAME">this._target</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">this._originalStyle.opacity</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>287</span> </span><span class="WHIT">      </span><span class="KEYW">delete</span><span class="PUNC">(</span><span class="NAME">this._originalStyle.opacity</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>288</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>289</span> </span><span class="WHIT">    </span><span class="NAME">MS.setStyle</span><span class="PUNC">(</span><span class="NAME">this._target</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">this._originalStyle</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">   </span><span class="WHIT">
<span class='line'>290</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>291</span> 
<span class='line'>292</span> </span><span class="WHIT">  </span><span class="COMM">/**
<span class='line'>293</span>    * @private
<span class='line'>294</span>    */</span><span class="WHIT">
<span class='line'>295</span> </span><span class="WHIT">  </span><span class="NAME">this._start</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">e</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>296</span> </span><span class="WHIT">  </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>297</span> </span><span class="WHIT">    </span><span class="NAME">this._event</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">e</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'>298</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">MS</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">MochiKit.Style</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>299</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">MD</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">MochiKit.DOM</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>300</span> </span><span class="WHIT">    </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">MB</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">MochiKit.Base</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>301</span> 
<span class='line'>302</span> </span><span class="WHIT">    </span><span class="COMM">// We need to remember what we're dragging</span><span class="WHIT">
<span class='line'>303</span> </span><span class="WHIT">    </span><span class="NAME">this._original</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">e.target</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'>304</span> 
<span class='line'>305</span> </span><span class="WHIT">    </span><span class="COMM">// Cache the offset</span><span class="WHIT">
<span class='line'>306</span> </span><span class="WHIT">    </span><span class="NAME">this._offset</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this._diff</span><span class="PUNC">(</span><span class="NAME">e.mouse</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">page</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'>307</span> </span><span class="WHIT">                              </span><span class="NAME">MS.getElementPosition</span><span class="PUNC">(</span><span class="NAME">this._original</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'>308</span> 
<span class='line'>309</span> 
<span class='line'>310</span> </span><span class="WHIT">    </span><span class="COMM">// Store the actual element we will drag</span><span class="WHIT">
<span class='line'>311</span> </span><span class="WHIT">    </span><span class="NAME">this._target</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">!</span><span class="NAME">MB.isUndefinedOrNull</span><span class="PUNC">(</span><span class="NAME">this.getClonedNode</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT">
<span class='line'>312</span> </span><span class="WHIT">                     </span><span class="NAME">this.getClonedNode</span><span class="PUNC">(</span><span class="NAME">e</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'>313</span> </span><span class="WHIT">                     </span><span class="NAME">this.cloneNode</span><span class="WHIT"> </span><span class="PUNC">?</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'>314</span> </span><span class="WHIT">                       </span><span class="NAME">this._original.cloneNode</span><span class="PUNC">(</span><span class="KEYW">true</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">:</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'>315</span> </span><span class="WHIT">                       </span><span class="NAME">this._original</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>316</span> 
<span class='line'>317</span> </span><span class="WHIT">    </span><span class="NAME">this._checkFuncEffects</span><span class="PUNC">(</span><span class="STRN">"getClonedNode"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>318</span> 
<span class='line'>319</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">MB.isUndefinedOrNull</span><span class="PUNC">(</span><span class="NAME">this._target.parentNode</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>320</span> </span><span class="WHIT">        </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="NAME">MD.appendChildNodes</span><span class="PUNC">(</span><span class="NAME">document.body</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">this._target</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>321</span> 
<span class='line'>322</span> </span><span class="WHIT">    </span><span class="COMM">// If we are not dragging the _original object, we need to set the </span><span class="WHIT">
<span class='line'>323</span> </span><span class="WHIT">    </span><span class="COMM">// position of the new object.</span><span class="WHIT">
<span class='line'>324</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">this._target</span><span class="WHIT"> </span><span class="PUNC">!=</span><span class="WHIT"> </span><span class="NAME">this._original</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>325</span> </span><span class="WHIT">    </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>326</span> </span><span class="WHIT">      </span><span class="NAME">this._drag</span><span class="PUNC">(</span><span class="NAME">e</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="KEYW">true</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>327</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>328</span> </span><span class="WHIT">     </span><span class="WHIT">
<span class='line'>329</span> </span><span class="WHIT">    </span><span class="COMM">// Cache the snap offset</span><span class="WHIT">
<span class='line'>330</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="NAME">this.snap</span><span class="WHIT"> </span><span class="PUNC">></span><span class="WHIT"> </span><span class="NUMB">1</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>331</span> </span><span class="WHIT">    </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>332</span> </span><span class="WHIT">      </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">tmpPos</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">MS.getElementPosition</span><span class="PUNC">(</span><span class="NAME">this._target</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>333</span> </span><span class="WHIT">      </span><span class="NAME">this._snapDiff</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">new</span><span class="WHIT"> </span><span class="NAME">MS.Coordinates</span><span class="PUNC">(</span><span class="NAME">tmpPos.x</span><span class="PUNC">%</span><span class="NAME">this.snap</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">tmpPos.y</span><span class="PUNC">%</span><span class="NAME">this.snap</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>334</span> </span><span class="WHIT">    </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>335</span> 
<span class='line'>336</span> </span><span class="WHIT">    </span><span class="COMM">// Store any current information about the object</span><span class="WHIT">
<span class='line'>337</span> </span><span class="WHIT">    </span><span class="NAME">this._originalStyle.opacity</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'>338</span> </span><span class="WHIT">      </span><span class="NAME">MS.getStyle</span><span class="PUNC">(</span><span class="NAME">this._target</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"opacity"</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>339</span> </span><span class="WHIT">    </span><span class="NAME">this._originalPosition</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">MS.getElementPosition</span><span class="PUNC">(</span><span class="NAME">this._original</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>340</span> 
<span class='line'>341</span> </span><span class="WHIT">    </span><span class="COMM">// Set any new information about the object</span><span class="WHIT">
<span class='line'>342</span> </span><span class="WHIT">    </span><span class="NAME">MS.setOpacity</span><span class="PUNC">(</span><span class="NAME">this._target</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">this.opacity</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">   </span><span class="WHIT">
<span class='line'>343</span> 
<span class='line'>344</span> </span><span class="WHIT">    </span><span class="KEYW">if</span><span class="PUNC">(</span><span class="PUNC">!</span><span class="NAME">MB.isUndefinedOrNull</span><span class="PUNC">(</span><span class="NAME">this.onStart</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="WHIT"> </span><span class="PUNC">{</span><span class="WHIT"> </span><span class="NAME">this.onStart</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>345</span> 
<span class='line'>346</span> </span><span class="WHIT">    </span><span class="COMM">// Cache the offset from the new element, in case the user changed it's position</span><span class="WHIT">
<span class='line'>347</span> </span><span class="WHIT">    </span><span class="NAME">this._offset</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">this._diff</span><span class="PUNC">(</span><span class="NAME">e.mouse</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">.</span><span class="NAME">page</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'>348</span> </span><span class="WHIT">                              </span><span class="NAME">MS.getElementPosition</span><span class="PUNC">(</span><span class="NAME">this._target</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'>349</span> 
<span class='line'>350</span> </span><span class="WHIT">    </span><span class="NAME">this._mousemove</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="NAME">MochiKit.Signal.connect</span><span class="PUNC">(</span><span class="NAME">document</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">'onmousemove'</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">this._drag</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'>351</span> </span><span class="WHIT">    </span><span class="NAME">this._mouseup</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT">   </span><span class="NAME">MochiKit.Signal.connect</span><span class="PUNC">(</span><span class="NAME">document</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">'onmouseup'</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">this._stop</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'>352</span> </span><span class="WHIT">    </span><span class="NAME">this._keyup</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT">   </span><span class="NAME">MochiKit.Signal.connect</span><span class="PUNC">(</span><span class="NAME">document</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">'onkeyup'</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">this._keyupfunc</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT"> </span><span class="WHIT">
<span class='line'>353</span> </span><span class="WHIT">    </span><span class="NAME">this._event</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">null</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>354</span> </span><span class="WHIT">  </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>355</span> 
<span class='line'>356</span> </span><span class="WHIT">  </span><span class="NAME">this._init</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>357</span> </span><span class="WHIT">  </span><span class="NAME">MochiKit.Base.setdefault</span><span class="PUNC">(</span><span class="KEYW">this</span><span class="PUNC">,</span><span class="NAME">options</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>358</span> </span><span class="WHIT">  </span><span class="NAME">MochiKit.Base.setdefault</span><span class="PUNC">(</span><span class="KEYW">this</span><span class="PUNC">,</span><span class="NAME">this._defaultOptions</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>359</span> </span><span class="WHIT">  </span><span class="NAME">MochiKit.Base.bindMethods</span><span class="PUNC">(</span><span class="KEYW">this</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>360</span> </span><span class="PUNC">}</span><span class="WHIT">
<span class='line'>361</span> 
<span class='line'>362</span> 
<span class='line'>363</span> </span><span class="COMM">/**
<span class='line'>364</span>  * @member org.brophy.js.drag.Dragger
<span class='line'>365</span>  * @description 
<span class='line'>366</span>  *   Apply a given Dragger object to the specified element.  This will 
<span class='line'>367</span>  *   make the specified element draggable with all of the properties of 
<span class='line'>368</span>  *   the given Dragger object.  You may set multiple elements draggable 
<span class='line'>369</span>  *   with the same Dragger and they will all behave the same.
<span class='line'>370</span>  *
<span class='line'>371</span>  * @param   elem  The element to make draggable
<span class='line'>372</span>  * @returns null
<span class='line'>373</span>  */</span><span class="WHIT">
<span class='line'>374</span> </span><span class="NAME">org.brophy.js.drag.Dragger.prototype.setElementDraggable</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="NAME">elem</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>375</span> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>376</span> </span><span class="WHIT">  </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">MochiKit.Signal.connect</span><span class="PUNC">(</span><span class="NAME">elem</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="STRN">"onmousedown"</span><span class="PUNC">,</span><span class="WHIT"> </span><span class="NAME">this._start</span><span class="PUNC">)</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>377</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>378</span> 
<span class='line'>379</span> </span><span class="COMM">/**
<span class='line'>380</span>  * Get the original node of the drag
<span class='line'>381</span>  * @returns The original node that was clicked on to start the drag
<span class='line'>382</span>  * @type Node
<span class='line'>383</span>  */</span><span class="WHIT">
<span class='line'>384</span> </span><span class="NAME">org.brophy.js.drag.Dragger.prototype.getOriginalNode</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>385</span> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>386</span> </span><span class="WHIT">  </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">this._original</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>387</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>388</span> 
<span class='line'>389</span> </span><span class="COMM">/**
<span class='line'>390</span>  * Get the target node of the drag
<span class='line'>391</span>  * @returns The actual node we are dragging, which may or may not the 
<span class='line'>392</span>  * the same as the original, based on the behavior of any specified 
<span class='line'>393</span>  * 'getClonedNode' function.
<span class='line'>394</span>  * @type Node
<span class='line'>395</span>  */</span><span class="WHIT">
<span class='line'>396</span> </span><span class="NAME">org.brophy.js.drag.Dragger.prototype.getTargetNode</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>397</span> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>398</span> </span><span class="WHIT">  </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">this._target</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>399</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>400</span> 
<span class='line'>401</span> </span><span class="COMM">/**
<span class='line'>402</span>  * Get the MochiKit Event that was fired
<span class='line'>403</span>  * @returns The MochiKit Event that was fired
<span class='line'>404</span>  * @type MochiKit Event object
<span class='line'>405</span>  */</span><span class="WHIT">
<span class='line'>406</span> </span><span class="NAME">org.brophy.js.drag.Dragger.prototype.getEvent</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="WHIT">
<span class='line'>407</span> </span><span class="PUNC">{</span><span class="WHIT">
<span class='line'>408</span> </span><span class="WHIT">  </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">this._event</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>409</span> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>410</span> 
<span class='line'>411</span> 
<span class='line'>412</span> </span></pre></body></html>